<?php

namespace app\common\model;

use think\Model;
use traits\model\SoftDelete;

class NewhouseStructure extends Model
{

    use SoftDelete;



    // 表名
    protected $name = 'newhouse_structure';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'status_text',
        'flag_text',
        'price_text'
    ];



    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3')];
    }

    public function getFlagList()
    {
        return ['0' => __('Flag 0'), '1' => __('Flag 1')];
    }

    public function getPriceList()
    {
        return ['0' => __('Price 0'), '1' => __('Price 1')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getFlagTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['flag']) ? $data['flag'] : '');
        $list = $this->getFlagList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPriceTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['price']) ? $data['price'] : '');
        $list = $this->getPriceList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function newhousecategory()
    {
        return $this->belongsTo('NewhouseCategory', 'category_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function newhouse()
    {
        return $this->belongsTo('Newhouse', 'newhouse_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function salelabel()
    {
        return $this->belongsTo('NewhouseLabel', 'salelabel_ids', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function ambientlabel()
    {
        return $this->belongsTo('NewhouseLabel', 'ambientlabel_ids', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
